package com.team.mp.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.team.mp.mapper.entity.ServiceinfoAudit;
import com.team.mp.mapper.dao.ServiceinfoAuditDao;
import com.team.mp.api.service.intf.ServiceinfoAuditService;
import com.team.mp.mapper.entity.ServiceinfoCancel;
import com.team.mp.mapper.entity.ServiceinfoFinished;
import com.team.mp.vo.R;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 千锋郑州Java学科欢迎你
 * @program: MyProject
 * @description: 业务接口实现层
 * @author: Xuerui
 * @create: 2023-03-27 20:08:52
 */
@Service
public class ServiceinfoAuditServiceImpl implements ServiceinfoAuditService{
    /**
    *注入持久层对象*/
    @Resource
    private ServiceinfoAuditDao dao;

    /**
    * 新增内容*/
    @Override
    public R save(ServiceinfoAudit serviceinfoAudit) {
        if(serviceinfoAudit !=null){
            ServiceinfoAudit audit = dao.selectOne(new QueryWrapper<ServiceinfoAudit>().eq("sid", serviceinfoAudit.getSid()));
            if (audit==null) {
                serviceinfoAudit.init();
                int i=dao.insert(serviceinfoAudit);
                if(i>0){
                    return R.ok();
                }
            }
            return R.fail("亲，新增异常！该服务信息已审核！");
        }
        return R.fail("亲，新增异常！");
    }
    /**
    * 修改内容*/
    @Override
    public R update(ServiceinfoAudit serviceinfoAudit) {
        if(serviceinfoAudit !=null){
            int i=dao.updateById(serviceinfoAudit);
             if(i>0){
                return R.ok();
              }
        }
        return R.fail("亲，修改异常！");
    }
    /**
    *删除 */
    @Override
    public R del(long id){
        if(id>0){
            int i=dao.deleteById(id);
            if(i>0){
                return R.ok();
            }
        }
        return R.fail("删除异常");
    }

    /**
    * 查询详情*/
    @Override
    public R queryById(long id){
        return R.ok(dao.selectById(id));
    }

    /**
     * 根据服务信息sid查询*/
    @Override
    public R queryBySid(Integer sid) {
        return R.ok(dao.selectOne(new QueryWrapper<ServiceinfoAudit>().eq("sid", sid)));
    }

    /**
    * 查询 所有数据*/
    @Override
    public R queryAll() {
      return R.ok(dao.selectList(null));
    }
}
